<%--
  Created by IntelliJ IDEA.
  User: daiyuhua
  Date: 2021/5/3
  Time: 21:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="<%=path%>/css/pintuer.css">
    <link rel="stylesheet" href="<%=path%>/css/admin.css">
    <link rel="stylesheet" href="<%=path%>/third/zTree_v3/css/zTreeStyle/zTreeStyle.css">
    <script src="<%=path%>/js/jquery.js"></script>
    <script src="<%=path%>/js/pintuer.js"></script>
    <script type="text/javascript" src="<%=path%>/third/zTree_v3/js/jquery.ztree.all.min.js"></script>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head"><strong><span class="icon-key"></span> 修改区域信息</strong></div>
    <div class="body-content">
        <form method="post" class="form-x" action="<%=path%>/editRole">
            <div class="form-group">
                <div class="label">
                    <label>区域编号：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" name="id" id="id"
                           value="${area.areaId}" readonly="readonly"/>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>区域名：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50"  name="areaname" id="areaname"
                           value="${area.areaName}"/>
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>区域所属：</label>
                </div>
                <div class="field">
                    <ul id="tree" class="ztree">
                        <input type="hidden" id="test" name="test"/>
                    </ul>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button class="button bg-main icon-check-square-o" type="submit" id="submit" onclick="editrole()"> 提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>
</html>
<script>
    $(function(){
        var setting={
            check: {
                chkboxType: {"Y":"p","N":"p"},
                enable: true,
                chkStyle: "checkbox"//显示 checkbox 选择框，默认checkbox可选择值radio
            },
            data: {
                simpleData:{
                    enable: true,
                    idKey: "id",
                    pIdKey: "areaFather",
                    rootPId: -1
                },
                key:{
                    name: "areaName"
                }
            }
        };
        $(document).ready(function () {
            $.ajax({
                type:"get",
                dataType: "json",
                url:"<%=path%>/findAllArea",
                async:true,
                success:function (res){
                    var zTreeObject = $.fn.zTree.init($("#tree"),setting,res.arealist);
                    zTreeObject.expandAll(true);
                }
            });
        });
    });
    function getCheck(){
        var zTree = $.fn.zTree.getZTreeObj("tree");
        var nodes = zTree.getCheckedNodes(true);
        var ids = ""
        for (var i in nodes){
            ids = ids + nodes[i].id + ",";
        }
        return ids
    }
    function savNodeRelation(){
        var ids = getCheck();
        document.form.test.value=ids;
    }
    function editrole() {
        var rolename = $("#areaname").val();
        console.log(rolename);
        savNodeRelation();
        $.ajax({
            url:"<%=path%>/editArea",
        })
    }
</script>
